<?php

namespace app\man\controller;

use think\Controller;
use think\Db;
use think\Paginator;
use think\Cache;
use think\Request;
class Domain extends Common
{
	public function dlist(){
		$type = input('did');
		if($type==1){
			$table='arrive_aicc';
		}elseif($type==2){
			$table='jump_aicc';
		}elseif($type==3){
			$table='vendor';
		}elseif($type==4){
			$table='vendor_ios';
		}elseif($type==5){
			$table = 'pro';
		}elseif($type==6){
			$table='ad';
		}
 
		$domains = Db::name($table)->paginate();

		$this->assign('list',$domains);

		$this->assign('type',$type);

		return $this->fetch('list');
	}

	public function add(){
		$type=input('did');
		$this->assign('type',$type);
		return $this->fetch('add');
	}
	public function doadd()
	{
		$type = input('type');
		if($type==1){
			$table='arrive_aicc';
		}elseif($type==2){
			$table='jump_aicc';
		}elseif($type==3){
			$table='vendor';
		}elseif($type==6){
			$table='ad';
		}
		$domains = input('domains');
		$lists = explode("\n",$domains);
		foreach($lists as $k=>$val){
			$data[$k]['domain']=trim($val);
			$data[$k]['status']=1;
			/*if($table=='vendor'){
				$data[$k]['accessKeyId']=$appid;
				$data[$k]['accessKeySecret']=$appkey;
			}*/
		}
		$result = Db::name($table)->insertAll($data);
		if($result){
			$this->success('添加成功', url('man/domain/add','did='.$type), 3);
		}else{
			$this->success('添加失败');
		}

	}
	public function delete(){
		$id = input('aid');
		$type=input('type');
		if($type==1){
			$table='arrive_aicc';
		}elseif($type==2){
			$table='jump_aicc';
		}elseif($type==3){
			$table='vendor';
		}elseif($type==4){
			$table='vendor_ios';
		}elseif($type==5){
			$table = 'pro';
		}elseif($type==6){
			$table='ad';
		}
		$res = Db::name($table)->where('id',$id)->delete();

		if($res){
			$this->success('删除成功', url('man/domain/dlist','did='.$type), 3);
		}else{
			$this->success('删除失败');
		}
	}
	public function change(){
		$aid=input('aid');
		$status=input('status');
		$type=input('type');
		if($type==1){
			$table='arrive_aicc';
		}elseif($type==2){
			$table='jump_aicc';
		}elseif($type==3){
			$table='vendor';
		}elseif($type==6){
			$table='ad';
		}
		if($status==2){
			$res = Db::name($table)->where('id',$aid)->update(['status'=>$status,'start_time'=>date('Y-m-d H:i:s')]);
		}else{
			$res = Db::name($table)->where('id',$aid)->update(['status'=>$status]);
		}

		if($status==3){
			$res = Db::name($table)->where('id',$aid)->update(['status'=>$status,'end_time'=>date('Y-m-d H:i:s')]);
		}else{
			$res = Db::name($table)->where('id',$aid)->update(['status'=>$status]);
		}
		if($status ==1){
			$res = Db::name($table)->where('id',$aid)->update(['status'=>$status]);
		}

		if($res===false){
			return false;
		}else{
			Cache::store('redis')->set('jeff_ad',NULL,1);
		if($res===false){
			return false;
		}else{
		return true;
		}
		}
	}

	public function cblur(){
		$nid = input('aid');

		$bek = input('bek');

		$res = Db::name('pro')->where('id',$nid)->update(['bek'=>$bek]);

		if($res){
			echo true;
		}else{
			echo false;
		}
	}
}